package com.eseo.munchkinarbiter;

public class FightStats {
	public GameData gameData;
	private int monsterLevel;
	private int monsterModifier;
	private int playerModifier;
	private PlayerStats helpPlayer;
	
	public FightStats(GameData gameData, int monsterLevel, int monsterModifier, int playerModifier) {
		this.gameData = gameData;
		this.monsterLevel = monsterLevel;
		this.monsterModifier = monsterModifier;
		this.playerModifier = playerModifier;
		this.helpPlayer = null;
	}

	public FightStats(GameData gameData) {
		this.gameData = gameData;
		this.monsterLevel = 1;
		this.monsterModifier = 0;
		this.playerModifier = 0;
		this.helpPlayer = null;
	}

	public int getMonsterLevel() {
		return monsterLevel;
	}

	public void setMonsterLevel(int monsterLevel) {
		this.monsterLevel = monsterLevel;
		gameData.onMonsterLevelChanged();
	}
	
	public int incMonsterLevel() {
		++monsterLevel;
		gameData.onMonsterLevelChanged();
		
		return monsterLevel;
	}
	
	public int decMonsterLevel() {
		if(monsterLevel <= 1)
			return monsterLevel;
		
		--monsterLevel;
		gameData.onMonsterLevelChanged();
		
		return monsterLevel;
	}

	public int getMonsterModifier() {
		return monsterModifier;
	}

	public void setMonsterModifier(int monsterModifier) {
		this.monsterModifier = monsterModifier;
		gameData.onMonsterModChanged();
	}
	
	public int incMonsterMod() {
		++monsterModifier;
		gameData.onMonsterModChanged();
		
		return monsterModifier;
	}
	
	public int decMonsterMod() {
		--monsterModifier;
		gameData.onMonsterModChanged();
		
		return monsterModifier;
	}

	public int getPlayerModifier() {
		return playerModifier;
	}

	public void setPlayerModifier(int playerModifier) {
		this.playerModifier = playerModifier;
		gameData.onPlayerModChanged();
	}
	
	public int incPlayerMod() {
		++playerModifier;
		gameData.onPlayerModChanged();
		
		return playerModifier;
	}
	
	public int decPlayerMod() {
		--playerModifier;
		gameData.onPlayerModChanged();
		
		return playerModifier;
	}
	
	public PlayerStats getHelpPlayer() {
		return helpPlayer;
	}
	
	public void setHelpPlayer(PlayerStats player) {
		this.helpPlayer = player;
		gameData.onHelpPlayerChanged();
	}
	
	public int getPlayerStrength() {
		if(gameData.getCurrentPlayer() == null)
			return 0;

		int str = gameData.getCurrentPlayer().getStrength();
		if(helpPlayer != null)
			str += helpPlayer.getStrength();
		
		return str;
	}
	
	public boolean getResult() {
		PlayerStats player = gameData.getCurrentPlayer();
		if(player == null) {
			return false;
		}
		
		int result = getPlayerModifier() + getPlayerStrength() - (getMonsterLevel() + getMonsterModifier());
		
		if(result > 0 || (result == 0 && player.isWarrior()))
			return true;
		else
			return false;
	}
	
	public void reset() {
		monsterLevel = 1;
		monsterModifier = 0;
		playerModifier = 0;
		helpPlayer = null;
	}
}
